const Router = [
    {
        title: '控制台',
        icon: 'laptop',
        key: '/index',
        role: ["user", "information", "product"]
    },
    {
        title: '用户管理',
        icon: 'laptop',
        key: '/index/user', // 菜单
        role: ["information", "user"], // 角色 
        child: [{
            key: '/index/user/list',
            title: '用户列表',
            icon: '',
            role: ["user"]
        },
        {
            key: '/index/user/add',
            title: '添加用户',
            icon: '',
            role: ["user"]
        }
        ]
    },
    {
        title: '部门管理',
        icon: 'bars',
        key: '/index/department',
        role: ["user"],
        child: [
            {
                key: '/index/department/list',
                title: '部门列表',
                icon: '',
                role: ["user"],
                child: [
                    {
                        key: '/index/department/a',
                        title: '部门列表1',
                        icon: '',
                        role: ["user"],
                        child: [
                            {
                                key: '/index/department/b',
                                title: '部门列表1-1',
                                icon: '',
                                role: ["user"],
                                child: [
                                    {
                                        key: '/index/department/bb',
                                        title: '部门列表1-1-1',
                                        icon: '',
                                        role: ["user"]
                                    },
                                    {
                                        key: '/index/department/cc',
                                        title: '添加部门1-1-2',
                                        icon: '',
                                        role: ["user"]
                                    },
                                ]
                            },
                            {
                                key: '/index/department/c',
                                title: '添加部门1-2',
                                icon: '',
                                role: ["user"]
                            },
                        ]
                    },
                    {
                        key: '/index/department/d',
                        title: '添加部门2',
                        icon: '',
                        role: ["user"]
                    },
                ]
            },
            {
                key: '/index/department/add',
                title: '添加部门',
                icon: '',
                role: ["user"]
            },
        ]
    },
    {
        title: '加班',
        icon: 'info-circle-o',
        key: '/home/abouta'
    }
]
const mmp = {}


const submenu = (title, key, child) => {
    mmp[title] = (
        child.map(item => {
            return renderSubMnenu(item)
        })
    )
    return title
    // return (
    //     child.map(item => {
    //         return renderSubMnenu(item)
    //     })
    // )
}

const menu = (title, key, child) => {
    mmp[title] = null
    return title
}

const renderSubMnenu = ({ title, key, child }) => {
    if (child) {

        return (
            submenu(title, key, child)
        )
    } else {
        return (
            menu(title, key, child)

        )
    }
}

// Router.map(firstItem => {
//     return renderSubMnenu(firstItem)
// })

forloop = (element) => {
    if (!element) {
        return
    }
    const tmp = {}
    // tmp = {} 上下这两句有很大的差别啊,无语...
    for (let index = 0; index < element.length; index++) {
        const em = element[index];
        tmp[em.title] = {}
        if (em.child) {
            tmp[em.title]['child'] = forloop(em.child)
        }
    }
    return tmp
}


tmp = forloop(Router)
console.log(tmp)
// console.log(tmp['部门管理'][0]['部门列表'])
console.log(mmp)
